package cn.tedu.shoot;
// 英雄机
import java.awt.image.BufferedImage;

public class Hero extends FlyingObject {
	private int life;      // 命
	private int doubleFire;// 火力值
    private BufferedImage[] images;//图片数组
    private int index;//协助图片切换
    public Hero(){
    	image =ShootGame.hero0;
	    width =image.getWidth();
	    height =image.getHeight();
	    x =150;
	    y =400;
	    life =3;
	    doubleFire =0;
	    images =new BufferedImage[]{ShootGame.hero0,ShootGame.hero1};
	    index =0;
    }
    /** */	
	public void step(){//10毫秒走一次
		//每100毫秒切换一次
		image =images[index++/10%images.length];//图片之间的切换根据个数（也就是数组长度）
	}
	
	//发射子弹
	public Bullet[] shoot(){
		int xStep =this.width/4;
		int yStep =20;
		if(doubleFire>0){//双倍
			Bullet[] bs =new Bullet[2];
			bs[0] =new Bullet(this.x+1*xStep,this.y-yStep);
			bs[1] =new Bullet(this.x+3*xStep,this.y-yStep);
			doubleFire-= 2;
			return bs;
		}else{//单倍
			Bullet[] bs =new Bullet[1];
			bs[0] =new Bullet(this.x+2*xStep,this.y-yStep);
			return bs;
		}
	}
	//英雄机随着鼠标移动
	public void moveTo(int x,int y){
		this.x =x-this.width/2;
		this.y =y-this.height/2;
	}
	/** 重写   是否越界*/
	public boolean outOfBounds(){
		return false;//永不越界
	}
	//增命
	public void addLife(){
		life++;
	}
	//得到命的值
	public int getLife(){
		return life;
	}
	//
	public void subtractLife(){
		life--;
	}
	
	public void addDoubleFire(){
		doubleFire+= 40;  
	}
	//清空火力值
	public void clearDoubleFire(){
		doubleFire =0;
	}
//英雄机被敌人撞	
	public boolean hit(FlyingObject other){
		int x1 =other.x-this.width;
		int x2 =other.x+other.width;
		int y1 =other.y-this.width;
		int y2 =other.y+other.height;
		int x =this.x;
		int y =this.y;
		
		return x>=x1 && x<=x2
				&&
			   y>=y1 && y<=y2;
	}
	

}
